//
//  UIView+BYView.m
//  KoolearnCET
//
//  Created by 崔宝印 on 2016/11/10.
//  Copyright © 2016年 Koolearn. All rights reserved.
//

#import "UIView+BYView.h"

@implementation UIView (BYView)
- (void)modify
{
    // $S:320 / 480 = 0.666667
    // 5S:320 / 568 = 0.563300
    // 6: 375 / 667 = 0562219
    // 6p:414 / 736 = 0.562500
    
    CGFloat fScreenWidth = [UIScreen mainScreen].bounds.size.width;
    CGFloat fScreenHeight = [UIScreen mainScreen].bounds.size.height;
    fScreenHeight = fScreenHeight > fScreenWidth ? fScreenHeight : fScreenWidth;
    CGFloat fScale = fScreenHeight / 667.0f;;
    //    if (fScreenHeight <= 480.0f || fScreenHeight == 667.f)
    //    {
    //        fScale = 480.0f / 667.0f;
    //    }
    //    else if (fScreenHeight == 568.0f)
    //    {
    //        fScale = 568.0f / 667.0f;
    //    }
    //    else if (fScreenHeight == 736.0f)
    //    {
    //        fScale = 736.0f / 667.0f;
    //    }
    //    else
    //    {
    //        fScale = 1.0f;
    //    }
//    NSLog(@"fScale = %f", fScale);
    
    NSArray *array = self.constraints;
    for (int i = 0; i < array.count; i++)
    {
        NSLayoutConstraint *constraint = [array objectAtIndex:i];
//        CGFloat ct = constraint.constant;
//        if (ct > 0)
        {
            constraint.constant *= fScale;
        }
//        NSLog(@"i = %d, 原值：constraint = %f，修复后：%f", i, ct,constraint.constant);
    }
    
    NSArray *subViews = [self subviews];
    if (subViews == nil || subViews.count <= 0)
    {
        return;
    }
    
    for (int iv = 0; iv < subViews.count; iv++)
    {
        UIView *subView = [subViews objectAtIndex:iv];
//        NSLog(@"subView = %d", (int)subView);
        [subView modify];
    }
}
@end
